<?php

/**
 * +------ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER * ---------+
 * +----------------------------------------------------------------------------+
 * | PHPKiisf - Keep It in Simple Framework										|
 * | Version 1.0																|
 * | Copyright (C) <2013>  Mario Cezzare <mcezzare@gmail.com>					|
 * | Blog: http://mcezzare.blogspot.com.br										|
 * |																			|
 * | This program is part of PHPKiisf, and is free software: you can			|
 * | redistribute it and/or modify it under the terms of the GNU 				|
 * | General Public License as published by										|
 * | the Free Software Foundation, either version 3 of the License, or			|
 * | (at your option) any later version.										|
 * |																			|
 * | This program is distributed in the hope that it will be useful,			|
 * | but WITHOUT ANY WARRANTY; without even the implied warranty of				|
 * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the				|
 * | GNU General Public License for more details.								|
 * | You should have received a copy of the GNU General Public License			|
 * | along with this program.  If not, see <http://www.gnu.org/licenses/>.		|
 * +----------------------------------------------------------------------------+
 * | Author : <Mario Cezzare Angelicola Chiodi> <mcezzare@gmail.com>			|
 * +----------------------------------------------------------------------------+
 * | Contributors																|
 * |																			|
 * +----------------------------------------------------------------------------+
 *
 */
/*
 * @package	Controllers
 * @access	public
 * @since	2013-04-29
 * @author	Mario Cezzare <mcezzare@gmail.com>
 */

/**
 * Message class of framework.
 *
 * Class used to send messages to user
 *
 */
class message {

    public $msg_type;
    public $msg_operation;
    public $msg_detail;
    public $msg_obs;

    public static function init() {

    }

    public function __get($name) {
	return $this->$name;
    }

    public function __set($name, $value) {
	$this->$name = $value;
    }

    public function message($msg_type, $msg_operation, $msg_detail, $msg_obs) {
	$this->msg_type = $msg_type;
	$this->msg_operation = $msg_operation;
	$this->msg_detail = $msg_detail;
	$this->msg_obs = $msg_obs;
	return $this;
    }

    /**
     * Create a message from array
     *
     * @param array $message
     * @return \message
     */
    public function create_message($message) {

	if (is_array($message)) {

	    $this->msg_type = isset($message{'MSG_TYPE'}) ? $message{'MSG_TYPE'} : null;
	    $this->msg_operation = isset($message{'OPERATION'}) ? $message{'OPERATION'} : null;
	    $this->msg_detail = isset($message{'DETAIL'}) ? $message{'DETAIL'} : null;
	    $this->msg_obs = isset($message{'OBS'}) ? $message{'OBS'} : null;
	}

	return $this;
    }

    public function get_msg_type() {
	return $this->msg_type;
    }

    public function set_msg_type($msg_type) {
	$this->msg_type = $msg_type;
	return $this;
    }

    public function get_msg_operation() {
	return $this->msg_operation;
    }

    public function set_msg_operation($msg_operation) {
	$this->msg_operation = $msg_operation;
	return $this;
    }

    public function get_msg_detail() {
	return $this->msg_detail;
    }

    public function set_msg_detail($msg_detail) {
	$this->msg_detail = $msg_detail;
	return $this;
    }

    public function get_msg_obs() {
	return $this->msg_obs;
    }

    public function set_msg_obs($msg_obs) {
	$this->msg_obs = $msg_obs;
	return $this;
    }

    public function __toString() {
	$final_message = sprintf("
Message Type: %s
Operation: %s
Details: %s
Notes:\n%s", $this->msg_type, $this->msg_operation, $this->msg_detail, $this->msg_obs);

	if ($this->msg_type == "ERROR") {
	    $final_message.= "<br><p style=\"font-size: 140%;\"> Please fix this and try again.</p>";
	}

	return $final_message;
    }

}

?>
